﻿#region Copyright 2011- Real Informática.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
//
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: Type.cs
#endregion

using System;
using System.Collections.Generic;

namespace estacionamento.comum
{
	/// <summary>
	/// Description of DefaultList.
	/// </summary>
	public abstract class DefaultList
	{
		protected String msgErro;	
		protected Int32 index;
		protected GenerateSql gsql;
		protected List<DefaultClass> items 		= new List<DefaultClass>();
		protected List<DefaultClass> normal 	= new List<DefaultClass>();
		protected List<DefaultClass> filtered = new List<DefaultClass>();		
		
		public DefaultList()
		{
			gsql = new GenerateSql();
			gsql.commandType = GenerateSql.TCommandType.CMD_SELECT;
			items = normal;
		}
		
		/// <summary>
		/// Get the error message
		/// </summary>
		/// <returns>String - the error message</returns>		
		public String errorMessage()
		{
			return msgErro;
		}	
		
		public Int32 getIndex()
		{
			return index;
		}
		
		public Int32 count()
		{
			return items.Count;
		}	
		
		public void clear()
		{
			items.Clear();
		}
		
		public void add(DefaultClass value)
		{
			items.Add(value);
		}		
		
		public void remove()
		{
			items.RemoveAt(index);
		}
		
		public bool removeAt(int index)
		{
			if(index < 0 || index >= items.Count)
			{
				return false;
			}
			items.RemoveAt(index);
			return true;
		}
		
		public void disableFilter()
		{
			items = normal;
		}	
		
		public bool search(String value)
		{
			int tam= items.Count;
			
			for (int i=0; i < tam; i++)
			{
				if ( items[i].id.Equals(value))
				{
					index= i;
					return true;
				}
			}
			return false;
		}		
	}
}
